package com.base.cn.platform.os.controller.qa.record;

import com.base.cn.platform.os.common.AdminBaseController;
import com.base.cn.platform.os.common.utils.DataUtil;
import com.base.cn.platform.os.service.course.qa.record.QaTeacherCashRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

/**
 * 老师申请分成记录Controller
 *
 * @author s.li
 * @date 2018/11/27
 */
@Controller
@RequestMapping("/admin/qa/teacher/cash")
public class AdminQaTeacherCashRecordController extends AdminBaseController {

    @Autowired
    private QaTeacherCashRecordService qaTeacherCashRecordService;

    /**
     * 老师问答分成记录
     * @return 操作页面
     */
    @RequestMapping("/queryCashRecordList")
    public String queryCashRecordList(){
        return resultPage("/qa/record/qa-cash-record-list");
    }

    /**
     * 加载数据
     * @param request HttpServletRequest
     * @param model Model
     * @param currentPage 页码
     * @param params 查询参数
     * @return 列表页面
     */
    @RequestMapping("/ajaxQueryCashRecordList")
    public String ajaxQueryCashRecordList(HttpServletRequest request,
                                          Model model,
                                          @RequestParam("currentPage") int currentPage,
                                          @RequestBody Map<String,Object> params){
        BigDecimal teacherId = loginUtil.getLoginUserTeacherId(request);
        if(DataUtil.idIsNotNull(teacherId)){
            params.put("teacherId",teacherId);
        }
        params.put("teacherData",true);
        Map<String,Object> dataMap = qaTeacherCashRecordService.findQaTeacherCashRecordPage(params,currentPage,10);
        model.addAttribute("dataMap",dataMap);
        return resultPage("/qa/record/ajax-qa-cash-record-list");
    }

    /**
     * 查看提现申请记录详情
     * @param id ID
     * @return 操作页面
     */
    @RequestMapping("/getTeacherCashRecordInfo")
    public String getTeacherCashRecordInfo(@RequestParam("id") BigDecimal id,Model model){
        Map<String,Object> params = new HashMap<>();
        params.put("id",id);
        params.put("teacherData",true);
        Map<String,Object> teacherCashRecord = qaTeacherCashRecordService.getTeacherCashRecordInfo(params);
        model.addAttribute("teacherCashRecord",teacherCashRecord);
        return resultPage("/qa/record/qa-cash-record-info");
    }

    /**
     * 查询问答提现详情的数据列表
     * @param params 查询参数
     * @param currentPage 页码
     * @return 操作列表页面
     */
    @RequestMapping("/getTeacherCashRecordInfoListData")
    public String getTeacherCashRecordInfoListData(Model model,
                                                   @RequestBody Map<String,Object> params,
                                                   @RequestParam("currentPage") int currentPage){
        int recordType = Integer.parseInt(params.get("recordType").toString());
        Map<String,Object> dataMap = qaTeacherCashRecordService.getTeacherCashRecordInfoListData(params,recordType,currentPage,10);
        model.addAttribute("dataMap",dataMap);
        model.addAttribute("recordType",recordType);
        return resultPage("/qa/record/ajax-qa-cash-record-data");
    }

    /**
     * 通过审核
     * @param id 记录ID
     * @return Map<String,Object>
     */
    @RequestMapping("/adopt")
    @ResponseBody
    public Map<String,Object> adopt(HttpServletRequest request,
                                    @RequestParam("id") BigDecimal id){
        BigDecimal sysUserId = loginUtil.getLoginUserId(request);
        return qaTeacherCashRecordService.adoptApply(id,sysUserId);
    }
}
